package com.app.simpsonux;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.widget.Toast;

public class UXUt
{

    public static void AlertDlg( Context aContext,
                          String  aTitle,
                          String  aMsg,
                          boolean aSimple )
    {
        if( aSimple == false )
        {
            new AlertDialog.Builder(aContext)
            .setTitle(aTitle).setMessage(aMsg)
            .setPositiveButton( "Ok",
                                 new DialogInterface.OnClickListener()
                                 {
                                     public void onClick( DialogInterface dialog,
                                                          int whichButton )
                                     {
                                         // Do nothing.
                                     }
                                 })
            .create().show();
        }
        else
        {
            Toast.makeText(aContext, aMsg, Toast.LENGTH_LONG).show();
        }
    }

    public static void ProgressDlg( Context aContext,
                                    final String  aTitle,
                                    final String  aMsg )
    {
        final Context sContext = aContext;
        AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>()
        {
            private ProgressDialog pd;
            @Override
            protected void onPreExecute()
            {
                pd = new ProgressDialog( sContext );
                pd.setTitle( aTitle );
                pd.setMessage( aMsg );
                pd.setCancelable( false );
                pd.setIndeterminate( true );
                pd.show();
            }
            @Override
            protected Void doInBackground( Void... arg0 )
            {
                try
                {
                    //Do something...
                    Thread.sleep(5000);
                }
                catch (InterruptedException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return null;
            }
            @Override
            protected void onPostExecute(Void result)
            {
                pd.dismiss();
            }
        };
        task.execute((Void[])null);
    }
    
}
